package com.hearwego;

import android.os.Bundle;
import android.support.v4.app.FragmentManager;
import android.support.v4.app.FragmentTransaction;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;

public class TabFragment extends BaseFragment {

    private static final int LIST_STATE = 0x1;
    private static final int GRID_STATE = 0x2;
    private static final int DESCR_STATE = 0x3;
    private int mTabState;

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.ac_fragment_tab, container, false);
        Button listViewTab = (Button) view.findViewById(R.id.list_view_tab);
        Button gridViewTab = (Button) view.findViewById(R.id.grid_view_tab);
        Button descripcionTab = (Button) view.findViewById(R.id.descripcion);

        gotoListView();
        listViewTab.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                gotoListView();
            }
        });
        gridViewTab.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
            gotoDetalleView();
            }
        });

        descripcionTab.setOnClickListener(new OnClickListener() {
            public void onClick(View v) {
                gotoDescriptionView();
            }
        });

        return view;
    }
    
    /********OBTENER EL ID DEL EVENTO DE LAS PREFERENCIAS CON EL NOMBRE "actualid"********/

protected void gotoDescriptionView() {
        if (mTabState != DESCR_STATE) {
            mTabState = DESCR_STATE;
            FragmentManager fm = getFragmentManager();
            if (fm != null) {
                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(R.id.fragment_content_header, new TabFragmentHeader());
                ft.replace(R.id.fragment_content, new DescripcionFragment());
                ft.commit();
            }
        }
}

public void gotoListView() {
        if (mTabState != LIST_STATE) {
            mTabState = LIST_STATE;
            FragmentManager fm = getFragmentManager();
            if (fm != null) {
                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(R.id.fragment_content_header, new TabFragmentHeader());
                ft.replace(R.id.fragment_content, new LocationListFragment());
                ft.commit();
            }
        }
    }

    public void gotoDetalleView() {
        if (mTabState != GRID_STATE) {
            mTabState = GRID_STATE;
            FragmentManager fm = getFragmentManager();
            if (fm != null) {
                FragmentTransaction ft = fm.beginTransaction();
                ft.replace(R.id.fragment_content_header, new TabFragmentHeaderDetalle());
                ft.replace(R.id.fragment_content, new DetalleFragment());
                ft.commit();
            }
        }
    }
}